问题
- 安卓返回键
- 页面之间传参数
- Vue页面生命周期
vue.js实现
<template>
//页面根节点
<div @onAndroidBack="onAndroidBack" @ready="ready" @actived="actived" @deactived="deactived" class="container">
</div>
</template>
<script>
methods: {
//页面ready 页面传参
ready(param){
let p = JSON.stringify(e.param)
console.log('pageA页面传参数=' + p);
},
//页面激活 param 页面传参
actived(param){
},
//页面失活
deactived(){
},
//
onAndroidBack(){
uNavigator.pop();
},
onClick(){
uNavigator.popTo({index:-1,tagCode:"pageb",param:{test:'testB'}},() => {} );
}
},
</script>
Android实现:
public void onBackPressed() {
WXComponent comp = mInstance.getRootComponent();
if (comp != null) {
WXEvent events = comp.getDomObject().getEvents();
boolean hasBack = events.contains(UConstants.Event.ONANDROIDBACK);
if (hasBack) {
WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ONANDROIDBACK, null, null);
return;
}else {
super.onBackPressed();
}
}
super.onBackPressed();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
if (intent == null) {
return;
}
if (intent.getStringExtra("params") != null) {
String params = intent.getStringExtra("params");
String backTag = intent.getStringExtra("backTag");
if (!TextUtils.isEmpty(params)) {
WXComponent comp = mInstance.getRootComponent();
if (comp != null) {
WXEvent events = comp.getDomObject().getEvents();
boolean hasActive = events.contains(UConstants.Event.ACTIVED);
if (hasActive) {
Map<String, Object> data = new HashMap<>();
data.put("param",params);
data.put("tagCode", backTag);
WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ACTIVED, data, null);
// }
}
}
}
}
}
@Override
public void onViewCreated(WXSDKInstance wxsdkInstance, View view) {
super.onViewCreated(wxsdkInstance, view);
WXComponent comp = mInstance.getRootComponent();
if (comp != null) {
WXEvent events = comp.getDomObject().getEvents();
boolean hasReady = events.contains(UConstants.Event.READY);
if (hasReady) {
Map<String, Object> data = new HashMap<>();
data.put("param", wxInfo.getParam());
WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.READY, data, null);
}
}
if (!isHasNavBar) {
setTranslateAnimation(getContainer());
}
}
@Override
public void onPause() {
super.onPause();
WXComponent comp = mInstance.getRootComponent();
if (comp != null) {
WXEvent events = comp.getDomObject().getEvents();
boolean hasDeactived = events.contains(UConstants.Event.DEACTIVED);
if (hasDeactived) {
WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.DEACTIVED, null, null);
}
}
if (mIsShakeDetectorStarted && mShakeDetector != null) {
mShakeDetector.stop();
mIsShakeDetectorStarted = false;
}
}
@Override
public void onResume() {
super.onResume();
if (!mIsShakeDetectorStarted && mShakeDetector != null) {
mShakeDetector.start((SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE));
mIsShakeDetectorStarted = true;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。